<?php
namespace app\merchant\controller\appeal;
use app\common\controller\BaseController;
use app\common\service\appeal\ShopOrderAppealService;
use app\common\validate\appeal\ShopOrderAppealValidate;
use hg\apidoc\annotation as Apidoc;
/**
 * @Apidoc\Title("申诉中心")
 * @Apidoc\Group("appeal")
 * @Apidoc\Sort("250")
 */
class ShopOrderAppeal extends BaseController
{
    /**
    * @Apidoc\Title("申诉中心列表")
    * @Apidoc\Query(ref="pagingQuery")
    * @Apidoc\Query(ref="sortQuery")
    * @Apidoc\Query(ref="searchQuery")
    * @Apidoc\Query(ref="dateQuery")
    * @Apidoc\Returned(ref="expsReturn")
    * @Apidoc\Returned(ref="pagingReturn")
    * @Apidoc\Returned("list", type="array", desc="申诉中心列表", children={
    *   @Apidoc\Returned(ref="app\common\model\appeal\ShopOrderAppealModel", field="id,is_disable,create_time,update_time,mer_id,shop_order_id,shop_order_on,setting_appeal_type_id,is_terminal,data_id,status,is_tip,remark")
    * })
    */
    public function list()
    {
        $where = $this->buildWhere([
            'is_terminal',
            'setting_appeal_type_id',
        ]);
        $where = $this->where(where_delete($where));
        $where[] = ['merchant_id','=',mer_id()];
        $data = ShopOrderAppealService::list($where, $this->page(), $this->limit(), $this->order());
        return success($data);
    }
    /**
    * @Apidoc\Title("申诉中心信息")
    * @Apidoc\Query(ref="app\common\model\appeal\ShopOrderAppealModel", field="id")
    * @Apidoc\Returned(ref="app\common\model\appeal\ShopOrderAppealModel")
    */
    public function info()
    {
        $param = $this->params(['id/d' => '']);
        validate(ShopOrderAppealValidate::class)->scene('info')->check($param);
        $data = ShopOrderAppealService::info($param['id']);
        return success($data);
    }
    /**
    * @Apidoc\Title("申诉中心添加")
    * @Apidoc\Method("POST")
    * @Apidoc\Param(ref="app\common\model\appeal\ShopOrderAppealModel", field="is_disable,mer_id,shop_order_id,shop_order_on,setting_appeal_type_id,is_terminal,data_id,status,is_tip,remark")
    */
    public function add()
    {
        $param = $this->params(ShopOrderAppealService::$edit_field);
        validate(ShopOrderAppealValidate::class)->scene('add')->check($param);
        $data = ShopOrderAppealService::add($param);
        return success($data);
    }
    /**
    * @Apidoc\Title("申诉中心修改")
    * @Apidoc\Method("POST")
    * @Apidoc\Param(ref="app\common\model\appeal\ShopOrderAppealModel", field="id,is_disable,mer_id,shop_order_id,shop_order_on,setting_appeal_type_id,is_terminal,data_id,status,is_tip,remark")
    */
    public function edit()
    {
        $param = $this->params(ShopOrderAppealService::$edit_field);
        validate(ShopOrderAppealValidate::class)->scene('edit')->check($param);
        $data = ShopOrderAppealService::edit($param['id'], $param);
        return success($data);
    }
    /**
    * @Apidoc\Title("申诉中心删除")
    * @Apidoc\Method("POST")
    * @Apidoc\Param(ref="idsParam")
    */
    public function dele()
    {
        $param = $this->params(['ids/a' => []]);
        validate(ShopOrderAppealValidate::class)->scene('dele')->check($param);
        $data = ShopOrderAppealService::dele($param['ids']);
        return success($data);
    }
    /**
     * @Apidoc\Title("申诉中心禁用")
     * @Apidoc\Method("POST")
     * @Apidoc\Param(ref="idsParam")
     * @Apidoc\Param(ref="app\common\model\appeal\ShopOrderAppealModel", field="is_disable")
     */
    public function disable()
    {
        $param = $this->params(['ids/a' => [], 'is_disable/d' => 0]);
        validate(ShopOrderAppealValidate::class)->scene('disable')->check($param);
        $data = ShopOrderAppealService::edit($param['ids'], $param);
        return success($data);
    }


    /**
     * @Apidoc\Title("申诉回复")
     * @Apidoc\Method("POST")
     * @Apidoc\Param(ref="app\common\model\appeal\ShopOrderAppealModel", field="id,is_disable,mer_id,shop_order_id,shop_order_on,setting_appeal_type_id,is_terminal,data_id,status,is_tip,remark")
     */
    public function reply()
    {
        $param = $this->params(['id/d' => null,'is_terminal/d' => 1, 'content/s' => '', 'image_ids/a' => []]);
        validate(ShopOrderAppealValidate::class)->scene('reply')->check($param);
        $data = ShopOrderAppealService::reply($param['id'], $param);
        return success($data);
    }
    /**
     * @Apidoc\Title("申诉完结")
     * @Apidoc\Method("POST")
     * @Apidoc\Param(ref="app\common\model\appeal\ShopOrderAppealModel", field="id,is_disable,mer_id,shop_order_id,shop_order_on,setting_appeal_type_id,is_terminal,data_id,status,is_tip,remark")
     */
    public function end()
    {
        $param = $this->params(['ids/a' => []]);
        validate(ShopOrderAppealValidate::class)->scene('end')->check($param);
        $data = ShopOrderAppealService::end($param['ids'],1);
        return success($data);
    }
}
